const app=getApp();
let videoContext;
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    openvideo:false,
    src:"",
    videoContext:{}
  },
  // 当切换模式改变
  attached(){
    this.setData({
      theme:app.theme,
      supplyChannel:app.supplyChannel
    })
  },
  ready(){
    this.data.videoContext = wx.createVideoContext('Products');
  },
  /**
   * 组件的方法列表
   */
  methods: {
    close(){
      let that=this;
      that.setData({
        openvideo:false
      })
      that.data.videoContext.seek= 0;
      that.data.videoContext.pause();
      
    },
    
    playVideo(e) {
      let that = this;
      if(app.functions.getLocalStorage("iscontinue") && app.functions.getLocalStorage("iscontinue")==true){
        that.setData({ 
          openvideo:true,
          src:e.videourl
        }, () => {
          that.data.videoContext.play()
        })
      }else{
        wx.getNetworkType({
          success: function(res) {
            var networkType = res.networkType;
            if (networkType == "wifi") {
              that.setData({ 
                src:e.videourl,
                openvideo:true
              }, () => {
                that.data.videoContext.play()
              })
            } else {
              wx.showModal({
                title: "温馨提示", //提示的标题,
                content: "当前无wifi，是否继续播放", //提示的内容,
                showCancel: true, //是否显示取消按钮,
                cancelText: "取消", //取消按钮的文字，默认为取消，最多 4 个字符,
                cancelColor: "#000000", //取消按钮的文字颜色,
                confirmText: "确定", //确定按钮的文字，默认为取消，最多 4 个字符,
                confirmColor: "#3CC51F", //确定按钮的文字颜色,
                success: res => {
                  if (res.confirm) {
                    app.functions.setLocalStorage("iscontinue",true);
                    that.setData({ 
                      src:e.videourl,
                      openvideo:true
                    }, () => {
                      that.data.videoContext.play()
                    })
                  }
                }
              });
            }
          }
        });
      }
    }
  }
})
